package com.jerome.rmi.enums;

/**
 * Scanner(System.in) Operation enumeration
 *
 * @author jerome
 * @date 2023/7/28
 */
public enum ScannerOperatorEnum {
    PUSH_VALUE(1, "pushValue"),
    PUSH_OPERATION(2, "pushOperation"),
    POP(3, "pop"),
    IS_EMPTY(4, "isEmpty"),
    DELAY_POP(5, "delayPop"),
    ;

    private int code;
    private String desc;

    ScannerOperatorEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static ScannerOperatorEnum getByCode(int code) {
        for (ScannerOperatorEnum value : ScannerOperatorEnum.values()) {
            if (value.code == code) {
                return value;
            }
        }
        return PUSH_VALUE;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static String string() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("Operator:");
        for (ScannerOperatorEnum value : ScannerOperatorEnum.values()) {
            stringBuilder.append(value.code).append(":").append(value.desc).append(" ");
        }
        return stringBuilder.toString();
    }
}
